﻿using System;
using Stee.Cap8.Service;
using SampleGrpcService;
using Grpc.Net.Client;
using System.Threading.Tasks;
using Grpc.Core;

namespace SampleGrpcClient
{
    class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");

            //check gRPC service health.
            var healthClient = new GrpcHealth.GrpcHealthClient(channel);
            var healthReply = await healthClient.CheckAsync(new HealthCheckRequest());
            Console.WriteLine("Health: " + healthReply.Status.ToString());

            var degradedReply= await healthClient.IsDegradedAsync(new ModeCheckRequest());
            Console.WriteLine("Degraded: " + degradedReply.Status.ToString());


            //set clientid, sessionid.
            var client = new Greeter.GreeterClient(channel);
            var metadata = new Metadata
            {
                {"x-requestid", Guid.NewGuid().ToString() },
               { "x-sessionid", Guid.NewGuid().ToString() }
        };
            var reply = await client.SayHelloAsync(new HelloRequest { Name = "Peter" }, metadata);
            Console.WriteLine("Greeting: " + reply.Message);

            Console.ReadKey();
        }
    }
}
